home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14322 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.4 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: WEIRD WEIRD Help Please a.s.a.p.:head pointers
  5. Date: Sat, 13 Apr 96 13:06:43 GMT
  6. Organization: none
  7. Message-ID: <829400803snz@genesis.demon.co.uk>
  8. References: <4km0vb$o04@badger.wmin.ac.uk>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4km0vb$o04@badger.wmin.ac.uk>
  15.            gsoec@wmin.ac.uk "Idoia Lertxundi" writes:
  16.  
  17. >Hi C sufferers/lovers,
  18. >
  19. >I am working in the C program and I have come accross a weird prob.
  20. >Rather than sending you code I will explain it in English as I have
  21. >accurately located the problem.
  22.  
  23. It is usually a much better idea to post code.
  24.  
  25. >I have a list which is being created dinamycally and a pointer pointing to
  26. >the head of the list. 
  27. >
  28. >ptr=AllocateSpaceforptr();
  29. >head=ptr;
  30. >
  31. > head  ptr....ptr
  32. > |   !   !  |
  33. > {}-{}-{}-NULL
  34. >
  35. >  1  2  3  4
  36. >
  37. >When I have put data in node number 3 I allocate with a malloc call
  38. >node number 4 and as the function do not find suitable data to put 
  39. >in number 4 after a for loop I assign it to NULL. i.e.
  40. >
  41. >     ptr=(FILEMODULE *)NULL;
  42.  
  43. What is ptr here? If it is a pointer that points to node 4 then assigning
  44. NULL to it simply loses the reference to node 4, it doesn't affect the
  45. contents of node 4.
  46.  
  47. >When I do printfs
  48.  
  49. What does 'do printfs' mean? What are you printing out and how?
  50.  
  51. >I see that the list of ptr corresponds to what I was
  52. >expecting the above picture when I print out the content of the head list
  53. >which points to the begining of the ptr list the result is unexpected.
  54. >i.e.
  55. >
  56. >head  
  57. > |   
  58. > {}-{}-{}-[] the last node instead of being NULL is not defined.
  59. >
  60. >  1  2  3  4
  61. >
  62. >By not defined I mean that is a if after malloc there has not been anything
  63. >put in there although I put the NULL which shows perfectly well in the ptr
  64. >list. Somehow the head list is not receiving the NULL asigment. WHY??
  65.  
  66. You're talking about a ptr list as if it is some separate entity. This is all
  67. very unclear. If you had posted code it would have been trivial to see what
  68. your mistake was. All we have here is your interpretation of what your
  69. code does which may itself be wrong.
  70.  
  71. -- 
  72. -----------------------------------------
  73. Lawrence Kirby | fred@genesis.demon.co.uk
  74. Wilts, England | 70734.126@compuserve.com
  75. -----------------------------------------
  76.